package com.inspur.gs.sbssdl.sbssbxgl.sbssbx.sbssbx.front.sbssbxfirstform_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bff.spi.*;
import com.inspur.edp.bef.api.action.*;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.condition.FilterCondition;
import com.inspur.edp.cef.entity.condition.FilterConditionBuilder;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.cef.entity.entity.IValuesContainer;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;
import io.iec.edp.caf.commons.utils.StringUtils;
import org.hibernate.mapping.Map;

import java.util.ArrayList;
import java.util.HashMap;

public class gzdhelpAfterVOAction extends AbstractFSAction<Object> {

	private String gzdbh;
	public gzdhelpAfterVOAction(String gzdbh) {

		this.gzdbh = gzdbh;
	}

	private static String gzjlid = "36d553b0-e4f7-4aeb-bdf9-c747396ab5a0";
	private static String sbtzid = "efd56b39-0e8d-4441-9fa1-2b019b6fd862";
	@Override
	public void execute() {
		//故障单后事件，找出故障单上的设备编号等信息，返回至前端
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			IStandardLcp lcp = iLcpFactory.createLcpByBEId(gzjlid);
			EntityFilter filter = new EntityFilter();
			ArrayList<FilterCondition> filterConditions = (ArrayList<FilterCondition>) FilterConditionBuilder
					.builder()
					.andEqual("Gzdh", gzdbh)
					.build();
			filter.addFilterConditions(filterConditions);
			IEntityData iEntityData = lcp.query(filter).get(0);
			String sbid = ((IValuesContainer)iEntityData.getValue("Sbid")).getValue("Sbid").toString();

			IStandardLcp tzlcp = iLcpFactory.createLcpByBEId(sbtzid);
			IEntityData data = tzlcp.retrieve(sbid).getData();
			String sbbh = null;
			String sbmc = null;
			String gzny = null;
			String cq = null;
			String sybm = null;
			if (data != null) {
				sbbh = data.getValue("sbbh") != null ? data.getValue("sbbh").toString() : null;
				sbmc = data.getValue("sbmc") != null ? data.getValue("sbmc").toString() : null;
				gzny = data.getValue("rzrq") != null ? data.getValue("rzrq").toString() : null;
				cq = ((IValuesContainer) data.getValue("shop_id")).getValue("shop_id_ShopName") != null ? ((IValuesContainer) data.getValue("shop_id")).getValue("shop_id_ShopName").toString() : null;
				sybm = ((IValuesContainer) data.getValue("bmbh_id")).getValue("bmbh_id_name") != null ? ((IValuesContainer) data.getValue("bmbh_id")).getValue("bmbh_id_name").toString() : null;
			}
			HashMap<String, String> map = new HashMap<>();
			map.put("sbbh", sbbh);
			map.put("sbmc", sbmc);
			map.put("gzny", gzny);
			map.put("cq", cq);
			map.put("sybm", sybm);
			setResult(map);
		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}

}
